package com.chuangke.metadata.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chuangke.common.db.page.CkPageQuery;
import com.chuangke.common.db.page.PageUtil;
import com.chuangke.framework.service.GridDictModelService;
import com.chuangke.framework.service.impl.GridDictModelServiceImpl;
import com.chuangke.metadata.dao.SysMoudleDao;
import com.chuangke.metadata.entity.SysMoudle;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SysMoudleService extends GridDictModelServiceImpl<SysMoudleDao, SysMoudle> {
    @Override
    public IPage<SysMoudle> page(CkPageQuery page) {
        List<SysMoudle> list = ((GridDictModelService) AopContext.currentProxy()).findList();
        String fuzzy = (String) page.get("name") ;
        if(!StrUtil.isBlank(fuzzy)) {
            list=list.stream().filter(item-> (item.getId().indexOf(fuzzy)!=-1||item.getName().indexOf(fuzzy)!=-1)).collect(Collectors.toList());
        }

        list = list.stream().sorted((o1, o2) -> o1.getSort().compareTo(o2.getSort())).collect(Collectors.toList());
        return PageUtil.findPage(page, list);
    }
}
